#! /bin/bash

bold=$(tput bold)
normal=$(tput sgr0)

read -p $'\e[36mNom du server\n\e[0m: ' \
     -e -i "Mon super serveur" server_name ;
     
read -p $'\e[36mMessage de bienvenue\n\e[0m: ' \
     -e -i "Bienvenue !" motd ;

read -p $'\e[36mDescription du serveur\n\e[0m: ' \
     -e -i "Un serveur avec plein de mods,..." \
    server_description ;

read -p $'\e[36mPort local\n\e[0m: ' \
     -e -i "30000" \
    port ;

read -p $'\e[36mNombre de max connexion simultanées\n\e[0m: ' \
     -e -i "10" \
    max_users ;

read -p $'\e[36mLanguage principal du serveur\n\e[0m: ' \
     -e -i "fr" \
    language ;
        
read -p $'\e[36mServeur en local uniquement ?\n\e[0m [oui/non]: ' \
     -e -i "non" local ;


case $local in 
  non) 

    read -p $'\e[36mPort distant\n\e[0m: ' \
         -e -i "30000" \
        remote_port ;

    read -p $'\e[36mAddresse distante\n\e[0m: ' \
         -e -i "127.0.0.1" \
        address ; 
         
    read -p $'\e[36mFaut-e -il annoncer le serveur dans la liste des serveur publics\n\e[0m [oui/non]: ' \
         -e -i "non" \
        annonce ;

  ;;
  *)
    remote_port='30000'
    address='127.0.0.1'
    annonce='non'
  ;;
esac

case $annonce in 
  oui) 
    read -p $'\e[36mAddresse publique\n\e[0m: ' \
         -e -i "$address" \
        server_address ; 
         
    read -p $'\e[36mEst-ce un serveur dédié ?\n\e[0m [oui/non]: ' \
         -e -i "non" \
        is_dedicated ;
        
    case is_dedicated in
      oui) server_dedicated='true' ;;
      oui) server_dedicated='false' ;;
    esac

    read -p $'\e[36mUrl du site web ou forum\e[0m (laisser vide si pas de site web)\n :' \
         -e -i "" \
        server_url ; 
  ;;
  *)
    server_dedicated='false'
    server_announce='false'
    server_address="$address"
    server_url=""
  ;;
esac


tee minetest.conf <<EOF

##-- Nom du serveur réglages de base
server_name = $server_name
motd = $motd
server_description = $server_description
port = $port
max_users = $max_users
language = $language

##-- Accès distant
address = $address
remote_port = $remote_port

server_dedicated = $server_dedicated
server_announce = $server_announce
server_address = $server_address

##-- Link to a webpage or forum thread
server_url = $server_url


##-- Debug
instrument.profiler = false
profiler.load = false
profiler.report_path = "profiler_data"
profiler_print_interval = 0

##-- Message à l'arret du serveur
kick_msg_shutdown = Arret du server (Server shutting down.)

EOF

cat settings/minetest.conf.server* >> minetest.conf
